import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'

import './assets/fonts/iconfont.css'

import './assets/css/global.css'

import axios from 'axios'

import TreeTable from 'vue-table-with-tree-grid'
import VueQuillEditor from 'vue-quill-editor'
// require styles
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

// 进度条插件
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

Vue.use(VueQuillEditor /* { default global options } */)

Vue.config.productionTip = false
axios.defaults.baseURL = 'https://www.liulongbin.top:8888/api/private/v1/'
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  NProgress.start()
  // 在发送请求之前做些什么
  const token = window.sessionStorage.getItem('token')
  if (token) {
    config.headers.Authorization = token
  }
  return config // 什么也没做原样返回
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error)
})

axios.interceptors.response.use(res => {
  NProgress.done()
  return res
})

Vue.component('TreeTable', TreeTable)

Vue.prototype.$http = axios

Vue.filter('dateFormat', function (time) {
  var dt = new Date(time * 1000)
  var y = dt.getFullYear()
  var m = (dt.getMonth() + 1).toString().padStart(2, '0')
  var d = (dt.getDate().toString().padStart(2, '0'))
  return `${y}年${m}月${d}日`
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
